"""
__author__ = '霍格沃兹测试开发学社'
__desc__ = '更多测试开发技术探讨，请访问：https://ceshiren.com/t/topic/15860'
"""
from flask import request
from flask_restx import Namespace, Resource

from service.testcase_service import TestcaseService

testcase_ns = Namespace("case", description="用例管理")
testcase_service = TestcaseService()


@testcase_ns.route("")
class TestcaseController(Resource):

    get_parser = testcase_ns.parser()
    get_parser.add_argument("id",type=int, location="args")
    @testcase_ns.expect(get_parser)
    def get(self):
        testcase_id = request.args.get("id")
        if testcase_id:
            data = [testcase_service.get(testcase_id).as_dict()]
        else:
            testcase_entity_list = testcase_service.get_all()
            data = [testcase.as_dict() for testcase in testcase_entity_list]
        return {"msg": data}

    def post(self):
        return {"msg": "post success"}

    def delete(self):
        return {"msg": "delete success"}

    def put(self):
        return {"msg": "update success"}